#-------------------------------------------------------------------------------
# Name:        pre
# Purpose:
#
# Author:      Administrator
#
# Created:     26/12/2012
# Copyright:   (c) Administrator 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------


import numpy
# input file only contains accepted result
# in the reverse order by submit
def load_last_n_correct(filename, n, udict):
    user_solved_problem_cnt=[0 for i in range(len(udict))]
    last_n_correct = [[0 for j in range(650)] for i in range(len(udict))]
    user_solved_problem = [[0 for j in range(650)] for i in range(len(udict))]
    with open (filename) as f:
        for line in f:
            [pid, uname, status] = line.split()
            pid = int(pid)
            uid = udict[uname]
            if user_solved_problem[uid][pid] == 0 :
                user_solved_problem_cnt[uid] += 1
                user_solved_problem[uid][pid] += 1
                if (user_solved_problem_cnt[uid] <= n):
                    last_n_correct[uid][pid] = 1

    last_n_correct= numpy.matrix(last_n_correct,numpy.double)
    return last_n_correct
def load_user_dict(user_file):
    user_dict={}
    user_list={}
    with open(user_file) as f:
        for line in f:
            [uid, uname] = line.split()
            user_dict[uname] = int(uid)
            user_list[int(uid)] = uname
    return [user_dict,user_list.values()]

def load_score(score_file):
    scores=[0 for i in range(650)]
    with open(score_file) as f:
        for line in f:
            [pid, score] = line.split()
            scores[int(pid)]=int(score)
    return scores

def get_user_done_score(user_matrix):
    user_matrix = numpy.matrix(user_matrix)
    done_score = numpy.divide([1],numpy.log2(user_matrix.sum(0) + 1))
    done_score[numpy.isinf(done_score)]=0
    return done_score

def test():
    pass

if __name__ == '__main__':
    test()
